package injector;

import annotation.ImplementedBy;

/**
 * Classe implementant Binding
 */
public class DefaultBinding<T> extends Binding<T> {

	public DefaultBinding(Class<T> iface) {
		super(iface);
	}

	@Override
	public boolean apply(Class<?> iface) {
		return iface == this.iface && iface.isAnnotationPresent(ImplementedBy.class);
	}

	@Override
	public T newInstance() {
		try {
			return (T) iface.getAnnotation(ImplementedBy.class).value().newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}

}
